<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

class CreateArticleCommentTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('article_comment', function (Blueprint $table) {
            $table->id();
            $table->text('address')->nullable()->comment('用户地址');
            $table->text('content')->nullable()->comment('评论内容');
            $table->timestamps();

             //添加外键字段
             $table->unsignedBigInteger("artid")->nullable()->comment('文章外键');

             //添加普通索引
             $table->index('artid', 'key_article_comment_artid');
 
             //建立外键关系
             $table->foreign('artid', 'fk_article_comment_artid')
                   ->references('id')
                   ->on('article')
                   ->constrained()
                   ->onUpdate('no action')
                   ->onDelete('cascade');
        });

        //表注释
        DB::statement("ALTER TABLE `pre_article_comment` comment '文章评论表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('article_comment');
    }
}
